﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<PublicMessage>>" %>
<%@ Import Namespace="Resources" %>
<%@ Import Namespace="ViewRes" %>
<script src="<%:Url.Content("~/Scripts/Diploma.js")%>" type="text/javascript"> </script>
<script src="<%:Url.Content("~/Scripts/Diploma.DialogHelper.js")%>" type="text/javascript"> </script>
<script type="text/javascript">
    function loadNextMessagesPortion() {
        var url = '<%:Url.RouteUrl("Default", new {controller = "PublicMessages", action = "Get"})%>' + '?startMessageId=' + $("#NextStartMessageId").val();

        $.ajax({
            url: url,
            method: 'GET',
            success: function (data) {
                if (data.length > 0) {
                    $("#NextStartMessageId").replaceWith(data);
                } else
                    $("#morePublicMessagesLink").remove();
            }
        });
    }

    $(function () {
        $("a.deleteLink").live("click", function () {
            deleteEntity(' <%:DiplomaResources.DoYouConfirmDeletion%>', publicMessageDeleted, $(this));

            return false;
        });
    });

    function publicMessageDeleted(senderA) {
        $(senderA).parents(".publicMessage").remove();
    }

</script>
<%
    if (!(ViewData["LoggedUser"] is Student))
    {%>
<script type="text/javascript">

    function addPublicMessage() {
        openDialog('<%:Url.RouteUrl("Default", new {controller = "PublicMessages", action = "Add"})%>', '<%:SharedStrings.Add%>', function () {

            $("#divDialog form").attr("onSuccess", "reloadMessages()");

        });
    }

    function reloadMessages() {
        var path = '<%:Url.RouteUrl("Default", new {controller = "PublicMessages", action = "Get"})%>';
        $("#publicMessagesContainer").load(path, function () {
        });
    }

</script>
<div class="addlink">
    <a href="javascript:void(0)" onclick=" addPublicMessage(); ">
        <%:SharedStrings.Add%>
    </a>
</div>
<%
    }%>
<div id="publicMessagesContainerWraper">
    <div id="publicMessagesContainer">
        <%
            if (Model != null && Model.Count() > 0)
            {%>
        <%
        Html.RenderPartial("~/Views/PublicMessages/PublicMessagesPortionControl.ascx", Model);%>
        <%
    } %>
        <%
    else
    {%>
        Нет сообщений
        <%
    }%>
    </div>
    <div>
        <a href="javascript:void(0)" id="morePublicMessagesLink" onclick=" loadNextMessagesPortion(); ">
            <h2>
                <%:SharedStrings.More%>...</h2>
        </a>
    </div>
</div>
